import { createApp } from 'vue'
import { createPinia } from 'pinia'
import ElementPlus from 'element-plus'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import 'element-plus/dist/index.css'
import App from './App.vue'
import router from './router'
import './assets/styles/index.scss'
import { useTagsViewStore } from './store/tagsView'
import { useThemeStore } from './store/theme'

// 创建全局标签操作方法
const tagsViewOperations = {
  closeSelectedTag(view) {
    const tagsViewStore = useTagsViewStore()
    return tagsViewStore.delView(view)
  },
  closeOthersTags(view) {
    const tagsViewStore = useTagsViewStore()
    return tagsViewStore.delOthersViews(view)
  },
  closeAllTags() {
    const tagsViewStore = useTagsViewStore()
    return tagsViewStore.delAllViews()
  },
  addVisitedView(view) {
    const tagsViewStore = useTagsViewStore()
    tagsViewStore.addVisitedView(view)
  }
}

const app = createApp(App)

// 注册所有图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}

app.use(createPinia())
app.use(router)
app.use(ElementPlus, { size: 'default', zIndex: 3000 })

// 初始化主题
const themeStore = useThemeStore()
themeStore.initTheme()

// 添加全局标签视图操作方法
app.config.globalProperties.$tagsView = tagsViewOperations

app.mount('#app')
